<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;

class PostController extends Controller {
//    文章列表
    public function index () {
//        dd(\Request::all());//门脸模式，静态方法//config/app.php=>aliases=>Request
//        $app = app();//获取容器
//        $log = $app->make("log");//获取日志类
//        $log->info('post_index', ['data'=>'this is post index']);
//        dd($log->info());
        \Log::info('post_rong', ['data'=>'this is post rong']);
        $posts = Post::orderBy('created_at', 'desc')->paginate(6);
        return view('post/index', compact('posts'));
    }

//    文章详情
    public function show (Post $post) {//依赖注入
        return view('post/show', compact('post'));
    }

//    创建文章
    public function create () {
        return view('post/create');
    }

    public function store () {

//        dd(\Request::all());
//        dd(request()->all());
//        $post = new Post();
//        $post->title = request('title');
//        $post->content = request('content');
//        $post->save();

//        $params = ['title'=>request('title'), 'content'=>request('content')];
//        Post::create($params);

        $result = Post::create(['title' => request('title'), 'content' => request('content')]);
        if ($result) {
            return redirect('/posts');
        }
    }

//    更新文章
    public function edit ($post) {
        return view('post/edit');
    }

    public function update () {

    }

//    删除文章
    public function delete ($post) {

    }
}
